<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Portfolio Management</title>
    </h:head>
    <h:body>
        <fieldset>
            <legend><h2>NEW TRANSACTION - BUYING AND SELLING OF SHARES</h2></legend>
            <h:form>
                <table cellpadding="5" border="0">
                    <tr>
                        <th>Company : </th>
                        <td>
                            <h:selectOneMenu value="#{shareManagementController.selectedCompany}">
                                <f:selectItems value="#{shareManagementController.companies}" var="item" itemValue="#{item}"></f:selectItems>
                            </h:selectOneMenu>
                        </td>
                        <th>Amount : </th>
                        <td>
                            <h:inputText value="#{shareManagementController.selectedAmount}" />
                        </td>
                        <td>
                            <h:commandButton value="Submit" action="#{shareManagementController.buyShares}" />
                        </td>
                    </tr>
                </table>
            </h:form>
        </fieldset>
        <fieldset>
            <legend><h2>SHARE TRANSACTION LIST</h2></legend>	
            <h:dataTable cellpadding="5" value="#{shareManagementController.shareTransactionList}" border="0" var="share" headerClass="header">
                <h:column>
                    <f:facet name="header">Company</f:facet>
                    <b>#{share.company}</b>
                </h:column>
                <h:column>
                    <f:facet name="header">Amount</f:facet>
                    #{share.amount}
                </h:column>
                <h:column>
                    <f:facet name="header">Price</f:facet>
                    #{share.price}
                </h:column>
                <h:column>
                    <f:facet name="header">Purchase Date</f:facet>
                    #{dateUtils.format(share.purchaseDate)}
                </h:column>
                <h:column>
                    <h:form>
                        <h:commandLink action="#{shareManagementController.deleteShareTransaction}">
                            <h:outputText value="Delete" />
                            <f:param name="transactionId" value="#{share.id}" />
                        </h:commandLink>
                    </h:form>
                </h:column>
            </h:dataTable>
        </fieldset>
        <fieldset>
            <legend><h2>PORTFOLIO DETAILS</h2></legend>
            <h:dataTable cellpadding="5" value="#{shareManagementController.portfolioDetails}" border="0" var="portfolio" headerClass="header">
                <h:column>
                    <f:facet name="header">Company</f:facet>
                    <b>#{portfolio.company}</b>
                </h:column>
                <h:column>
                    <f:facet name="header">Price per Share</f:facet>
                    #{portfolio.price}
                </h:column>
                <h:column>
                    <f:facet name="header">Total Shares</f:facet>
                    <center>#{portfolio.amount}</center>
                </h:column>
                <h:column>
                    <f:facet name="header">Total value</f:facet>
                    #{portfolio.totalValue}
                </h:column>
            </h:dataTable>
        </fieldset>
    </h:body>
</html>
